package emergency.adapter;

import com.orm.SugarRecord;

import java.util.ArrayList;
import java.util.List;

import model.Emergency;

/**
 * Created by Administrator on 2016/4/6.
 */
public class DBEmergencyAdapter {
    List<Emergency> emergencys = new ArrayList<Emergency>();

    long lastId;

    public void setEmergencys(List<Emergency> emergencys) {
        this.emergencys = emergencys;
    }

    // 初始化
    public void init()
    {
        List<Emergency> emergencies = SugarRecord.listAll(Emergency.class,"id desc limit 0,40");
        emergencys.addAll(emergencies);
        if (!emergencies.isEmpty())
        {
            Emergency last = emergencies.get(emergencies.size() - 1);
            lastId = last.getId();
        }
    }

    public int getOld()
    {
        List<Emergency> emergencies = SugarRecord.findWithQuery(Emergency.class,"Select * from Emergency where id < ? order by id desc limit 0,40",lastId+"");
        emergencys.addAll(emergencies);
        if (!emergencies.isEmpty())
        {
            Emergency last = emergencies.get(emergencies.size() - 1);
            lastId = last.getId();
        }
        return emergencies.size();
    }

}
